package com.lap.framework.generator.domain.template.strategy;

import com.lap.framework.generator.application.assembler.Transformer;
import com.lap.framework.generator.domain.FileModel;
import com.lap.framework.generator.domain.TemplateModel;
import com.lap.framework.generator.domain.template.CodeContext;
import com.lap.framework.generator.domain.template.CodeTemplate;
import com.lap.framework.generator.domain.template.TemplateGenerator;
import com.lap.framework.generator.domain.valueobject.CodeType;
import java.util.List;

public class PersistencePo implements CodeTemplate<FileModel> {

  @Override
  public CodeType getType() {
    return CodeType.DRIVING;
  }

  @Override
  public List<FileModel> generate(CodeContext context) {
    TemplateModel model = Transformer.transform(context.tableMeta(), context.envConfig());
    String[] persistencePoPackName = {
      model.getBasePackage(), "adapter.driving.persistence", model.getModule(), "po"
    };
    String[] persistencePoFileName = {model.getClassName(), "Po"};

    String[] convertPackName = {
      model.getBasePackage(), "adapter.driving.persistence", model.getModule()
    };
    String[] converterFileName = {model.getClassName(), "Converter"};

    return List.of(
        TemplateGenerator.generateFile(
            model,
            persistencePoPackName,
            persistencePoFileName,
            "java",
            "adapter/driving/PersistencePo.java.ftl"),
        TemplateGenerator.generateFile(
            model,
            convertPackName,
            converterFileName,
            "java",
            "adapter/driving/PersistenceConverter.java.ftl"));
  }
}
